﻿using System;
using System.Globalization;
using System.Web;
using System.Web.UI;

namespace BookingEngine.Web.en
{
    public partial class Booking : Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            var hotelCode = Request.QueryString["p"];
            var checkInDate = Request.QueryString["I"];
            var checkOutDate = Request.QueryString["O"];
            var adultsNumber = Request.QueryString["A"];

            HttpContext.Current.Session["HotelCode"] = string.IsNullOrEmpty(hotelCode) ? string.Empty : hotelCode.Trim();
            HttpContext.Current.Session["CheckInDate"] = (string.IsNullOrEmpty(checkInDate) ? DateTime.Now.Date.AddDays(1) : DateTime.Parse(checkInDate)).ToString("yyyy-MM-dd");
            HttpContext.Current.Session["CheckOutDate"] = (string.IsNullOrEmpty(checkOutDate) ? DateTime.Now.Date.AddDays(2) : DateTime.Parse(checkOutDate)).ToString("yyyy-MM-dd");
            HttpContext.Current.Session["AdultsNumber"] = (string.IsNullOrEmpty(adultsNumber) ? 1 : int.Parse(adultsNumber)).ToString(CultureInfo.InvariantCulture);
            HttpContext.Current.Session["Culture"] = "en-US";

            HttpContext.Current.Application["HotelCode"] = string.IsNullOrEmpty(hotelCode) ? string.Empty : hotelCode.Trim();
            HttpContext.Current.Application["CheckInDate"] = (string.IsNullOrEmpty(checkInDate) ? DateTime.Now.Date.AddDays(1) : DateTime.Parse(checkInDate)).ToString("yyyy-MM-dd");
            HttpContext.Current.Application["CheckOutDate"] = (string.IsNullOrEmpty(checkOutDate) ? DateTime.Now.Date.AddDays(2) : DateTime.Parse(checkOutDate)).ToString("yyyy-MM-dd");
            HttpContext.Current.Application["AdultsNumber"] = (string.IsNullOrEmpty(adultsNumber) ? 1 : int.Parse(adultsNumber)).ToString(CultureInfo.InvariantCulture);
            HttpContext.Current.Application["Culture"] = "en-US";

            //if (Response.Cookies["HotelCode"] != null)
            //{
            //    Response.Cookies.Remove("HotelCode");
            //    Response.Cookies.Add(new HttpCookie("HotelCode", string.IsNullOrEmpty(hotelCode) ? string.Empty : hotelCode.Trim()));
            //}
            //if (Response.Cookies["CheckInDate"] != null)
            //{
            //    Response.Cookies.Remove("CheckInDate");
            //    Response.Cookies.Add(new HttpCookie("CheckInDate", (string.IsNullOrEmpty(checkInDate) ? DateTime.Now.Date.AddDays(1) : DateTime.Parse(checkInDate)).ToString("yyyy-MM-dd")));
            //}
            //if (Response.Cookies["CheckOutDate"] != null)
            //{
            //    Response.Cookies.Remove("CheckOutDate");
            //    Response.Cookies.Add(new HttpCookie("CheckOutDate", (string.IsNullOrEmpty(checkOutDate) ? DateTime.Now.Date.AddDays(2) : DateTime.Parse(checkOutDate)).ToString("yyyy-MM-dd")));
            //}
            //if (Response.Cookies["AdultsNumber"] != null)
            //{
            //    Response.Cookies.Remove("AdultsNumber");
            //    Response.Cookies.Add(new HttpCookie("AdultsNumber", (string.IsNullOrEmpty(adultsNumber) ? 1 : int.Parse(adultsNumber)).ToString(CultureInfo.InvariantCulture)));
            //}
            //if (Response.Cookies["Culture"] != null)
            //{
            //    Response.Cookies.Remove("Culture");
            //    Response.Cookies.Add(new HttpCookie("Culture", "en-US"));
            //}
            Response.Redirect("~/SearchRate.wgx");
        }
    }
}